package com.xiaoxin.controller;

import com.xiaoxin.model.dto.RecommendUserDto;
import com.xiaoxin.model.vo.NearUserVo;
import com.xiaoxin.model.vo.PageResult;
import com.xiaoxin.model.vo.TodayBest;
import com.xiaoxin.service.MongoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author xiaoxiaode
 * @date 2021-09-01-15:09
 **/

@RestController
@RequestMapping("/tanhua")
public class MongoController {

    @Autowired
    private MongoService mongoService;

    /*
     * 查看今日佳人
     * */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = mongoService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /*
     * 查询分页推荐好友列表
     * */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto recommendUserDto) {
        PageResult pg = mongoService.recommendation(recommendUserDto);
        return ResponseEntity.ok(pg);
    }

    /*
     * 查询佳人详情
     * */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId) {
        TodayBest todayBest = mongoService.personalInfo(userId);
        return ResponseEntity.ok(todayBest);
    }

    /*
     * 查看陌生人问题
     * */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
        String questions = mongoService.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }

    /*
     * 回复陌生人问题
     * */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map) {
        String id = map.get("userId").toString();
        Long userId = Long.valueOf(id);
        String reply = map.get("reply").toString();
        mongoService.reply(userId, reply);
        return ResponseEntity.ok(null);
    }

    /*
     * card推荐列表
     * */
    @GetMapping("/cards")
    public ResponseEntity cards(){
        List<TodayBest> todayBests=mongoService.recommendCards();
        return ResponseEntity.ok(todayBests);
    }


    /*
     * card推荐-喜欢
     * */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id")Long likeUserId){
        mongoService.love(likeUserId);
        return ResponseEntity.ok(null);
    }

    /*
     * card推荐-不喜欢
     * */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id")Long unlikeUserId){
        mongoService.unlove(unlikeUserId);
        return ResponseEntity.ok(null);
    }

    /*
    * 搜附近
    * */
    @GetMapping("/search")
    public ResponseEntity search(String gender,
                                 @RequestParam(defaultValue = "1000") String distance){
        List<NearUserVo> list = this.mongoService.queryNearUser(gender, distance);
        return ResponseEntity.ok(list);
    }
}
